package com.corona.game;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Vector2;
import com.corona.Game;
import com.corona.game.util.TextureCache;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;

/* compiled from: Menu.java */
/* loaded from: pokewilds.jar:com/pkmngen/game/DrawPlayerMenu.class */
public class DrawPlayerMenu extends Menu {
    public static int lastIndex = 0;
    Sprite helperSprite;
    public Action.Layer layer = Action.Layer.gui_108;
    int cursorDelay = 0;
    Map<Integer, Vector2> arrowCoords = new HashMap();
    ArrayList<ArrayList<Sprite>> spritesToDraw = new ArrayList<>();
    Sprite arrow = new Sprite(TextureCache.get(Gdx.files.internal("battle/arrow_right1.png")), 0, 0, 5, 7);
    Sprite arrowWhite = new Sprite(TextureCache.get(Gdx.files.internal("battle/arrow_right_white.png")), 0, 0, 5, 7);
    Sprite textBox = new Sprite(TextureCache.get(Gdx.files.internal("menu/menu6.png")), 0, 0, 160, 144);
    Vector2 newPos = this.arrowCoords.get(Integer.valueOf(this.currIndex));
    String[] entries = {"POKéMON", "ITEM", "MAP", "GUIDE", "SAVE"};

    public DrawPlayerMenu(Game game, Action nextAction) {
        this.disabled = false;
        this.drawArrowWhite = false;
        this.nextAction = nextAction;
        this.arrowCoords.put(0, new Vector2(89.0f, 120.0f));
        this.arrowCoords.put(1, new Vector2(89.0f, 104.0f));
        this.arrowCoords.put(2, new Vector2(89.0f, 88.0f));
        this.arrowCoords.put(3, new Vector2(89.0f, 72.0f));
        this.arrowCoords.put(4, new Vector2(89.0f, 56.0f));
        this.currIndex = lastIndex;
        this.arrow.setPosition(this.newPos.x, this.newPos.y);
        for (String entry : this.entries) {
            char[] textArray = entry.toCharArray();
            int i = 0;
            int j = 0;
            ArrayList<Sprite> word = new ArrayList<>();
            for (char letter : textArray) {
                Sprite letterSprite = game.textDict.get(Character.valueOf(letter));
                Sprite currSprite = new Sprite(letterSprite == null ? game.textDict.get(null) : letterSprite);
                currSprite.setPosition((float) (96 + (8 * i)), (float) (120 - (8 * j)));
                word.add(currSprite);
                if (i >= 17) {
                    i = 0;
                    j++;
                } else {
                    i++;
                }
            }
            this.spritesToDraw.add(word);
        }
    }

    @Override // com.corona.game.Action
    public String getCamera() {
        return "gui";
    }

    @Override // com.corona.game.Action
    public Action.Layer getLayer() {
        return this.layer;
    }

    @Override // com.corona.game.Action
    public void step(Game game) {
        game.uiBatch.draw(this.textBox, this.textBox.getX(), this.textBox.getY());
        int j = 0;
        Iterator<ArrayList<Sprite>> it = this.spritesToDraw.iterator();
        while (it.hasNext()) {
            Iterator<Sprite> it2 = it.next().iterator();
            while (it2.hasNext()) {
                Sprite sprite = it2.next();
                game.uiBatch.draw(sprite, sprite.getX(), sprite.getY() - ((float) (j * 16)));
            }
            j++;
        }
        if (!this.disabled) {
            if (InputProcessor.upJustPressed) {
                if (this.currIndex > 0) {
                    this.currIndex--;
                    this.newPos = this.arrowCoords.get(Integer.valueOf(this.currIndex));
                }
            } else if (InputProcessor.downJustPressed && this.currIndex < 4) {
                this.currIndex++;
                this.newPos = this.arrowCoords.get(Integer.valueOf(this.currIndex));
            }
            if (InputProcessor.aJustPressed) {
                game.actionStack.remove(this);
                game.insertAction(new PlayMusic("click1", (Action) null));
                this.disabled = true;
                String currEntry = this.entries[this.currIndex];
                if (currEntry.equals("POKéMON")) {
                    game.insertAction(new DrawPokemonMenu.Intro(new DrawPokemonMenu(game, this)));
                } else if (currEntry.equals("ITEM")) {
                    DrawItemMenuGen2 menu = new DrawItemMenuGen2(game, this);
                    menu.disabled = true;
                    game.insertAction(new DrawItemMenu.Intro(this, 6, new DrawWhiteScreen(18, new DrawItemMenu.Intro(menu, 9, new RunCode(() -> {
                        menu.disabled = false;
                    }, menu)))));
                } else if (currEntry.equals("MAP")) {
                    game.insertAction(new DrawMiniMap.Intro(this, 9, new DrawMiniMap(game, this)));
                } else if (currEntry.equals("GUIDE")) {
                    game.insertAction(new DrawItemMenu.Intro(this, 9, new DrawItemMenu(game, true, this)));
                } else if (currEntry.equals("SAVE")) {
                    game.map.saveToFileNew(game);
                    game.insertAction(new DisplayText(game, game.player.name.toUpperCase(Locale.ROOT) + " saved the game!", "save1.ogg", (Action) null, new WaitFrames(game, 6, new SetField(game, "playerCanMove", true, new SetField(game.player, "canMove", true, null)))));
                }
            } else if (InputProcessor.bJustPressed || InputProcessor.startJustPressed) {
                lastIndex = this.currIndex;
                game.actionStack.remove(this);
                game.insertAction(this.nextAction);
                game.insertAction(new PlayMusic("click1", (Action) null));
            }
            if (this.cursorDelay >= 2) {
                game.uiBatch.draw(this.arrow, this.newPos.x, this.newPos.y);
            } else {
                this.cursorDelay++;
            }
        } else if (this.drawArrowWhite) {
            this.arrowWhite.setPosition(this.newPos.x, this.newPos.y);
            this.arrowWhite.draw(game.uiBatch);
        }
    }

    /* compiled from: Menu.java */
    /* loaded from: pokewilds.jar:com/pkmngen/game/DrawPlayerMenu$Intro.class */
    public static class Intro extends Action {
        Sprite sprite;
        String sound;
        Sprite helperSprite;
        public Action.Layer layer = Action.Layer.gui_120;
        ArrayList<Sprite> sprites = new ArrayList<>();
        ArrayList<Integer> repeats = new ArrayList<>();
        ArrayList<String> sounds = new ArrayList<>();

        public Intro(Game game, Action nextAction) {
            super(new Object[0]);
            this.nextAction = nextAction;
            Texture text = TextureCache.get(Gdx.files.internal("menu/menu6.png"));
            this.sprite = new Sprite(text, 0, 0, 160, 144);
            this.repeats.add(17);
            this.sounds.add(null);
        }

        @Override // com.corona.game.Action
        public String getCamera() {
            return "gui";
        }

        @Override // com.corona.game.Action
        public Action.Layer getLayer() {
            return this.layer;
        }

        @Override // com.corona.game.Action
        public void step(Game game) {
            game.uiBatch.draw(this.sprite, this.sprite.getX(), this.sprite.getY());
            if (this.repeats.isEmpty()) {
                game.insertAction(new PlayMusic("menu_open1", (Action) null));
                game.insertAction(this.nextAction);
                game.actionStack.remove(this);
                return;
            }
            this.sound = this.sounds.get(0);
            if (this.sound != null) {
                game.insertAction(new PlayMusic("menu_open1", (Action) null));
                this.sounds.set(0, null);
            }
            if (this.repeats.get(0).intValue() > 1) {
                this.repeats.set(0, Integer.valueOf(this.repeats.get(0).intValue() - 1));
                return;
            }
            this.repeats.remove(0);
            this.sounds.remove(0);
        }
    }
}
